
********************
*** Main figures ***
********************

** Figure 1 - clicks over time, over traffic and total traffic **

use "final_dataset.dta", clear
sort municipality pubmonth

preserve 

collapse views norviews, by(pubmonth)
sort pubmonth
gen time=_n
label define date 1 "Feb15" 2 "Mar15" 3 "Apr15" 4 "May15" 5 "Jun15" 6 "Jul15" 7 "Ago15" 8 "Sep15" 9 "Oct15" 10 "Nov15" 11 "Dec15" 12 "Jan16" 13 "Feb16"
label values time date
format norviews* %9.2f

preserve
/* dataset total traffic available after signing disclosure agreement with DN */
import excel "tot_pageviews.xlsx", firstrow clear
drop if county=="(not set)" | city=="(not set)"
collapse tot_views, by(month_year)
gen time=_n
label define date 1 "Feb15" 2 "Mar15" 3 "Apr15" 4 "May15" 5 "Jun15" 6 "Jul15" 7 "Ago15" 8 "Sep15" 9 "Oct15" 10 "Nov15" 11 "Dec15" 12 "Jan16" 13 "Feb16"
label values time date
save "totaltraffic.dta",replace
restore

merge 1:1 time using "totaltraffic.dta"
replace tot_views=tot_views/1000
gen crisis=400
label var crisis "Refugee crisis"
label var tot_views "Total DN traffic"
label var norviews "Refugee clicks over total traffic"
label var views "Refugee clicks"

twoway (area crisis time if time>=7 & time<=11, color(gs14) )(line tot_views time, ///
lpattern(dash) lcolor(navy)) (line norviews time, yaxis(2) lcolor(maroon)) ///
(line views time, lpattern(shortdash)), ytitle("Average refugee clicks over total traffic", axis(2)) ///
ylabel(0(0.02)0.1, axis(2)) ytitle("Average refugee clicks per article" "Total DN traffic") ///
ylabel(, nogrid) xtitle("") xlabel(1(1)13, valuelabel angle(45))graphregion(color(white) lwidth(large))
graph export "figure1.pdf", replace

restore


** Figure 2 - Refugees national average changes over time **

use "final_refugeesMunicip.dta", clear

keep  change_ratio_refugees* time municipality
sort time municipality
collapse change_ratio_refugees*, by(time)

label define date 1 "Dec14" 2 "Jan15" 3 "Feb15" 4 "Mar15" 5 "Apr15" 6 "May15" 7 "Jun15" 8 "Jul15" 9 "Ago15" 10 "Sep15" 11 "Oct15" 12 "Nov15" 13 "Dec15" 14 "Jan16" 15 "Feb16" 16 "Mar16"
label values time date
label var change_ratio_refugees "Total asylum seekers"
label var change_ratio_refugeesABO "Asylum seekers - Migration housing"
label var change_ratio_refugeesEBO "Asylum seekers - Own housing"

twoway (line change_ratio_refugees time if time!=1 &  time!=2 & time!=16) ///
(line change_ratio_refugeesABO time if time!=1 & time!=2 & time!=16, lpattern(dash)) ///
(line change_ratio_refugeesEBO time if time!=1 & time!=2 & time!=16, lpattern(shortdash)) , ///
ytitle("Average of monthly changes in asylum seekers per capita", size(small)) ylabel(, nogrid) xtitle("") ///
xlabel(3(1)15, valuelabel angle(45)) legend(size(small)) graphregion(color(white) lwidth(large))
graph export "figure2.pdf", replace


** Figure 4 - Parallel trend **

use "final_dataset.dta", clear

preserve 

collapse norviews, by(pubmonth above_median)

sort above_median pubmonth
bysort above_median: gen time=_n
label define date 1 "Feb15" 2 "Mar15" 3 "Apr15" 4 "May15" 5 "Jun15" 6 "Jul15" 7 "Ago15" 8 "Sep15" 9 "Oct15" 10 "Nov15" 11 "Dec15" 12 "Jan16" 13 "Feb16"
label values time date
format norviews* %9.2f
gen crisis=0.16

twoway (area crisis time if time>=7 & time<=8, color(gs14) ) ///
(line norviews time if above_median==0, lpattern(dash) lcolor(navy)) ///
(line  norviews time if above_median==1, lcolor(maroon)), ///
ytitle("Average refugee clicks over total traffic") ///
ylabel(, nogrid) xtitle("") xlabel(1(1)13, valuelabel angle(45)) ///
legend(label (1 "Beginning of crisis") label(2 "Below median") label(3 "Above median")) ///
graphregion(color(white) lwidth(large)) 
graph export "figure4.pdf", replace

restore


** Figure 5 - Parallel trend by article type **

use "final_dataset_classified.dta", clear

preserve 

collapse norviews, by(flyktingar pubmonth above_median)

sort flyktingar above_median pubmonth
bysort flyktingar above_median: gen time=_n
label define date 1 "Feb15" 2 "Mar15" 3 "Apr15" 4 "May15" 5 "Jun15" 6 "Jul15" 7 "Ago15" 8 "Sep15" 9 "Oct15" 10 "Nov15" 11 "Dec15" 12 "Jan16" 13 "Feb16"
label values time date
format norviews* %9.2f
gen crisis=0.15

twoway (area crisis time if time>=7 & time<=8, color(gs14)) ///
 (line norviews time if above_median==0 & flyktingar==0, lpattern(dash_dot) lcolor(navy)) ///
 (line  norviews time if above_median==1 & flyktingar==0, lpattern(dash) lcolor(blue)) ///
 (line norviews time if above_median==0 & flyktingar==1, lpattern(shortdash) lcolor(maroon)) ///
 (line  norviews time if above_median==1 & flyktingar==1, lcolor(red)), ///
ytitle("Average refugee clicks over total traffic" " ") ///
ylabel(, nogrid) xtitle("") xlabel(1(1)13, valuelabel angle(45)) ///
legend(label (1 "Beginning of crisis") label(2 "Below median/Non-empathic") label(3 "Above median/Non-empathic") ///
label(4 "Below median/Empathic") label(5 "Above median/Empathic") size(small)) ///
graphregion(color(white) lwidth(large)) 
graph export "figure5.pdf", replace

restore

** Figure 6 - effect by month **

use "final_dataset.dta", clear

gen feb1=1 if pubmonth==201502
replace feb1=0 if pubmonth!=201502
gen mar=1 if pubmonth==201503
replace mar=0 if pubmonth!=201503
gen apr=1 if pubmonth==201504
replace apr=0 if pubmonth!=201504
gen may=1 if pubmonth==201505
replace may=0 if pubmonth!=201505
gen jun=1 if pubmonth==201506
replace jun=0 if pubmonth!=201506
gen jul=1 if pubmonth==201507
replace jul=0 if pubmonth!=201507
gen aug=1 if pubmonth==201508
replace aug=0 if pubmonth!=201508
gen sep=1 if pubmonth==201509
replace sep=0 if pubmonth!=201509
gen oct=1 if pubmonth==201510
replace oct=0 if pubmonth!=201510
gen nov=1 if pubmonth==201511
replace nov=0 if pubmonth!=201511
gen dec=1 if pubmonth==201512
replace dec=0 if pubmonth!=201512
gen jan=1 if pubmonth==201601
replace jan=0 if pubmonth!=201601

gen inter1=c.ratio_refugees#feb1
gen inter2=c.ratio_refugees#mar
gen inter3=c.ratio_refugees#apr
gen inter4=c.ratio_refugees#may
gen inter5=c.ratio_refugees#jun
gen inter6=c.ratio_refugees#jul
gen inter7=c.ratio_refugees#aug
gen inter8=c.ratio_refugees#sep
gen inter9=c.ratio_refugees#oct
gen inter10=c.ratio_refugees#nov
gen inter11=c.ratio_refugees#dec
gen inter12=c.ratio_refugees#jan

label var inter1 "Feb15"
label var inter2 "Mar15"
label var inter3 "Apr15"
label var inter4 "May15"
label var inter5 "Jun15"
label var inter6 "Jul15"
label var inter7 "Aug15"
label var inter8 "Sep15"
label var inter9 "Oct15"
label var inter10 "Nov15"
label var inter11 "Dec15"
label var inter12 "Jan16"

xtreg norviews inter*,fe vce(cluster id)
estimates store crisis

coefplot crisis, addplot(line  @b @at, lpattern(dash) lcolor(black)) vert drop(_cons) xline(8, lwidth(medthick) lcolor(gs13)) label graphregion(color(white) lwidth(large))
graph export "figure6.pdf", replace

** Figure 7 - number of articles **

preserve

use "num_articles.dta",clear
sort pubmonth
drop if pubmonth==201501 | pubmonth==.
gen time=_n
label define date 1 "Feb15" 2 "Mar15" 3 "Apr15" 4 "May15" 5 "Jun15" 6 "Jul15" 7 "Ago15" 8 "Sep15" 9 "Oct15" 10 "Nov15" 11 "Dec15" 12 "Jan16" 13 "Feb16"
label values time date

graph bar numarticle, over(time, label(angle(45))) ylabel(, nogrid)  ///
ytitle("Total number of refugee articles") graphregion(color(white) lwidth(large))
graph export "figure7.pdf", replace

restore
